********************************************************************************
// PCSAs
********************************************************************************

clear all
set more off 
set seed 12345
cap log close
log using "BR_EntryThreshold_PCSA_F.log", replace

// Descriptives

use "PCSALevelData_v3.dta", clear
replace cat_aucc = og_n_hospaffucc_geo
replace cat_aucc = 2 if cat_aucc>2
replace n_hospaffucc_geo = cat_aucc

// Appendix Table 2
tabstat tot_pop rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured cms_wage_index any_hosp any_aucc, by(cat_ucc) stat(mean sd) columns(stat)
// Appendix Table 4
tabstat tot_pop rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured cms_wage_index any_hosp any_ucc, by(cat_aucc) stat(mean sd) columns(stat)

// Programs

capture program drop brentry
qui do "brentry_v2.do"
capture program drop brentry_bioprobit_neg
qui do "brentry_bioprobit_negbin_v3.do"

putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
putexcel A1 = "2-type"
putexcel B1 = "Low income"
putexcel C1 = "High income"
putexcel D1 = "High SVI"
putexcel E1 = "Low SVI"
putexcel F1 = "High uninsured"
putexcel G1 = "Low uninsured"
putexcel H1 = "1-type"
putexcel I1 = "3-type"
putexcel J1 = "Low income"
putexcel K1 = "High income"
putexcel L1 = "High SVI"
putexcel M1 = "Low SVI"
putexcel N1 = "High uninsured"
putexcel O1 = "Low uninsured"

********************************************************************************
// Ordered probit: no endogeneity
********************************************************************************

constraint drop 
constraint 1 tot_pop = 1
ml clear
ml model lf brentry (ucc_s:cat_ucc = tot_pop, nocons) (ucc_v:cat_ucc = n_hospitals rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3, constraints(1)
eststo clear
eststo: ml max, difficult iterate(100) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
qui do "BR_EntryThreshold_og.do" 10000 "H"
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]

********************************************************************************
// Multivariate ordered probit: addressing endogeneity
********************************************************************************

constraint drop
constraint 1 tot_pop = 1
constraint 2 tot_pop2 = 1
ml clear
ml model lf brentry_bioprobit_neg (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 = rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 /r, constraints(1 2) technique(bfgs)
eststo: ml max, difficult iterate(200) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
do "BR_EntryThreshold_Bi.do" 10000 10000 "A"
do "BR_EntryThreshold_Bi_Conditional.do" 10000 10000 0
do "BR_EntryThreshold_Bi_Conditional.do" 10000 10000 1
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r)

estout *, drop(tot_pop*) cells("b(fmt(1)) se(fmt(1))") label mlabels("Univariate" "Bivariate")

********************************************************************************
// Subsample analysis
********************************************************************************

// Income

ml clear
ml model lf brentry_bioprobit_neg (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 = rural hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals rural hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 /r if high_income==0, constraints(1 2)
eststo clear
eststo: ml max, difficult iterate(100) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
do "BR_EntryThreshold_Bi_Income.do" 10000 10000 "B" 0
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r)

ml clear
ml model lf brentry_bioprobit_neg (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 = rural hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals rural hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 /r if high_income==1, constraints(1 2) technique(bfgs)
eststo: ml max, difficult iterate(300) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
do "BR_EntryThreshold_Bi_Income.do" 10000 10000 "C" 1
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r)

// SVI categories

ml clear
ml model lf brentry_bioprobit_neg (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 = rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 /r if high_svi==1, constraints(1 2)
eststo: ml max, difficult iterate(300) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
do "BR_EntryThreshold_Bi_svi.do" 10000 10000 "D" 1
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r)

ml clear
ml model lf brentry_bioprobit_neg (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 =  rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 /r if high_svi==0, constraints(1 2)
eststo: ml max, iterate(100) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
do "BR_EntryThreshold_Bi_svi.do" 10000 10000 "E" 0
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r)

// Uninsured

ml clear
ml model lf brentry_bioprobit_neg (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 = rural income_pc hispanic nonhisp_black gte_highschool age_65, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals rural income_pc hispanic nonhisp_black gte_highschool age_65, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 /r if high_uninsured==1, constraints(1 2)
eststo: ml max, difficult iterate(100) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
do "BR_EntryThreshold_Bi_Uninsured.do" 10000 10000 "F" 1
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r)

ml clear
ml model lf brentry_bioprobit_neg (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 = rural income_pc hispanic nonhisp_black gte_highschool age_65, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals rural income_pc hispanic nonhisp_black gte_highschool age_65, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 /r if high_uninsured==0, constraints(1 2)
eststo: ml max, difficult iterate(100) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
do "BR_EntryThreshold_Bi_Uninsured.do" 10000 10000 "G" 0
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r)

estout *, drop(tot_pop*) cells(b(fmt(1)) se(fmt(1))) label mlabels("Low income" "High income" "High SVI" "Low SVI" "High uninsured" "Low uninsured")

********************************************************************************
// 3-type model
********************************************************************************

clear all
use "PCSALevelData_v3.dta", clear
capture program drop brentry_bioprobit_neg_3t
qui do "brentry_bioprobit_negbin_3t_v2.do"

replace cat_aucc = og_n_hospaffucc_geo
replace cat_aucc = 2 if cat_aucc>2
replace n_hospaffucc_geo = cat_aucc

constraint drop
constraint 1 tot_pop = 1
constraint 2 tot_pop2 = 1
constraint 3 tot_pop3 = 1
constraint 4 /r1 = /r2
constraint 5 /r2 = /r3
ml clear
ml model lf brentry_bioprobit_neg_3t (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 = rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals n_hospaffucc_geo rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 (aucc_s:cat_aucc = tot_pop3, nocons) (aucc_v:cat_aucc = n_hospitals n_urgentcare rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (aucc_f:cat_aucc = cms_wage_index, nocons) /aucc_a1 /aucc_a2 /aucc_g1 /aucc_g2 /r1 /r2 /r3, constraints(1 2 3 4 5)
eststo clear
eststo: ml max, difficult iterate(300) tolerance(1e-3) ltolerance(1e-4)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
qui do "BR_EntryThreshold_Bi_3t.do" 10000 10000 10000 "I"
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r1)

do "BR_EntryThreshold_Bi_3t_cond.do" 10000 10000 10000 0 0
do "BR_EntryThreshold_Bi_3t_cond.do" 10000 10000 10000 1 0
do "BR_EntryThreshold_Bi_3t_cond.do" 10000 10000 10000 1 1
do "BR_EntryThreshold_Bi_3t_cond.do" 10000 10000 10000 1 2

estout *, drop(tot_pop*) cells("b(fmt(1)) se(fmt(1))") label mlabels("3-type")

// 3-type model in subsamples

* Income

ml clear
ml model lf brentry_bioprobit_neg_3t (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 = rural hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals n_hospaffucc_geo rural hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 (aucc_s:cat_aucc = tot_pop3, nocons) (aucc_v:cat_aucc = n_hospitals n_urgentcare rural hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (aucc_f:cat_aucc = cms_wage_index, nocons) /aucc_a1 /aucc_a2 /aucc_g1 /aucc_g2 /r1 /r2 /r3 if high_income==0, constraints(1 2 3 4 5) technique(bfgs)
eststo clear
eststo: ml max, difficult iterate(300) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
qui do "BR_EntryThreshold_Bi_3t_Income.do" 10000 10000 10000 "J" 0
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r1)

ml clear
ml model lf brentry_bioprobit_neg_3t (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 = rural hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals n_hospaffucc_geo rural hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 (aucc_s:cat_aucc = tot_pop3, nocons) (aucc_v:cat_aucc = n_hospitals n_urgentcare rural hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (aucc_f:cat_aucc = cms_wage_index, nocons) /aucc_a1 /aucc_a2 /aucc_g1 /aucc_g2 /r1 /r2 /r3 if high_income==1, constraints(1 2 3 4 5) technique(bfgs)
eststo: ml max, difficult iterate(300) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
qui do "BR_EntryThreshold_Bi_3t_Income.do" 10000 10000 10000 "K" 1
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r1)

* SVI

ml clear
ml model lf brentry_bioprobit_neg_3t (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 = rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals n_hospaffucc_geo rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 (aucc_s:cat_aucc = tot_pop3, nocons) (aucc_v:cat_aucc = n_hospitals n_urgentcare rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (aucc_f:cat_aucc = cms_wage_index, nocons) /aucc_a1 /aucc_a2 /aucc_g1 /aucc_g2 /r1 /r2 /r3 if high_svi==1, constraints(1 2 3 4 5) technique(bfgs) 
eststo: ml max, difficult iterate(300) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
qui do "BR_EntryThreshold_Bi_3t_SVI.do" 10000 10000 10000 "L" 1
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r1)

ml clear
ml model lf brentry_bioprobit_neg_3t (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 = rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals n_hospaffucc_geo rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 (aucc_s:cat_aucc = tot_pop3, nocons) (aucc_v:cat_aucc = n_hospitals n_urgentcare rural income_pc hispanic nonhisp_black gte_highschool age_65 uninsured, nocons) (aucc_f:cat_aucc = cms_wage_index, nocons) /aucc_a1 /aucc_a2 /aucc_g1 /aucc_g2 /r1 /r2 /r3 if high_svi==0, constraints(1 2 3 4 5) technique(bfgs) 
eststo: ml max, difficult iterate(300) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
qui do "BR_EntryThreshold_Bi_3t_SVI.do" 10000 10000 10000 "M" 0
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r1)

* Uninsured

ml clear
ml model lf brentry_bioprobit_neg_3t (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 = rural income_pc hispanic income_pc nonhisp_black gte_highschool age_65, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals n_hospaffucc_geo rural hispanic income_pc nonhisp_black gte_highschool age_65, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 (aucc_s:cat_aucc = tot_pop3, nocons) (aucc_v:cat_aucc = n_hospitals n_urgentcare rural hispanic income_pc nonhisp_black gte_highschool age_65, nocons) (aucc_f:cat_aucc = cms_wage_index, nocons) /aucc_a1 /aucc_a2 /aucc_g1 /aucc_g2 /r1 /r2 /r3 if high_uninsured==1, constraints(1 2 3 4 5) technique(bfgs)
eststo: ml max, difficult iterate(100) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
qui do "BR_EntryThreshold_Bi_3t_Uninsured.do" 10000 10000 10000 "N" 1
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r1)

ml clear
ml model lf brentry_bioprobit_neg_3t (hosp_s:cat_hosp2 = tot_pop, nocons) (hosp_v:cat_hosp2 = rural income_pc hispanic nonhisp_black gte_highschool age_65, nocons) (hosp_f:cat_hosp2 = cms_wage_index con_intensity, nocons) /hosp_a1 /hosp_g1 (ucc_s:cat_ucc = tot_pop2, nocons) (ucc_v:cat_ucc = n_hospitals n_hospaffucc_geo rural income_pc hispanic nonhisp_black gte_highschool age_65, nocons) (ucc_f:cat_ucc = cms_wage_index, nocons) /ucc_a1 /ucc_a2 /ucc_a3 /ucc_g1 /ucc_g2 /ucc_g3 (aucc_s:cat_aucc = tot_pop3, nocons) (aucc_v:cat_aucc = n_hospitals n_urgentcare rural income_pc hispanic nonhisp_black gte_highschool age_65, nocons) (aucc_f:cat_aucc = cms_wage_index, nocons) /aucc_a1 /aucc_a2 /aucc_g1 /aucc_g2 /r1 /r2 /r3 if high_uninsured==0, constraints(1 2 3 4 5) technique(bfgs)
eststo: ml max, difficult iterate(300) tolerance(1e-4) ltolerance(1e-5)
putexcel set "BR_EntryThreshold_Results_V7.xlsx", modify sheet("entry")
qui do "BR_EntryThreshold_Bi_3t_Uninsured.do" 10000 10000 10000 "O" 0
lincom _b[/ucc_g1] + _b[/ucc_g2]
lincom _b[/ucc_g1] + _b[/ucc_g2] + _b[/ucc_g3]
lincom _b[/ucc_a1] - _b[/ucc_a2]
lincom _b[/ucc_a1] - _b[/ucc_a2] - _b[/ucc_a3]
nlcom atanh(/r1)

estout *, drop(tot_pop*) cells(b(fmt(1)) se(fmt(1))) label mlabels("Low income" "High income" "High SVI" "Low SVI" "High uninsured" "Low uninsured")

log close
